package Top4.mandatory;

import com.rabbitmq.client.*;
import util.ConnectionUtil;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeoutException;

/**
 * @Auther: Administrator
 * @Date: 2019/2/27 15:01
 * @Description:
 */
public class TTLproducer {
    private static final String EXCHANGE_NAME = "mandatory_exchange_demo";
    private static final String ROUTING_KEY = "mandatory_routingkey_demo";
    private static final String QUEUE_NAME = "mandatory_queue_demo";


    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connection = ConnectionUtil.getConnection();
        Channel channel = connection.createChannel();

        String message = "TTL Test";
        //发送时候调用的是路由键
        // 创建一个 type="direct" 、持久化的、非自动删除的交换器
        channel.exchangeDeclare(EXCHANGE_NAME, "direct", true, false, null);
        Map<String, Object> argss = new HashMap<String, Object>();
        argss.put("x-messager-ttl", 6000);
        // 持久化的 非排他的  非自动删的队列
        channel.queueDeclare(QUEUE_NAME, true, false, false, argss);


        channel.basicPublish(EXCHANGE_NAME, ROUTING_KEY, true, MessageProperties.PERSISTENT_TEXT_PLAIN, message.getBytes());

        connection.close();
    }
}
